//
//  KKCommentView.m
//  DoMi
//
//  Created by 康凯 on 2016/11/9.
//  Copyright © 2016年 kk. All rights reserved.
//

#import "KKCommentView.h"
#import "KKCommentM.h"
#import "KKCommentCell.h"
#import "KKReplyVC.h"

@interface KKCommentView()<UITableViewDelegate,UITableViewDataSource>
@property(copy,nonatomic)NSString *flag;
@end

@implementation KKCommentView

-(void)initView:(CGFloat)height{
    [self setFrame:CGRectMake(0, 0, screenWidth, height)];
    [self.commentTableView setFrame:CGRectMake(0, 0, screenWidth, height-50)];
    self.commentTableView.delegate=self;
    self.commentTableView.dataSource=self;
    [self.commentTableView registerNib:[UINib nibWithNibName:@"KKCommentCell" bundle:nil] forCellReuseIdentifier:@"KKCommentCell"];
}

#pragma mark 更新数据
-(void)refreshData:(NSArray *)datas flag:(NSString *)flag{
    self.commentDatas=datas;
    [self.commentTableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationNone];
}

#pragma mark tableview delegate
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    KKCommentCell *comment=(KKCommentCell *)cell;
    [comment initData:self.commentDatas[indexPath.row]];
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.commentDatas.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    return [tableView dequeueReusableCellWithIdentifier:@"KKCommentCell"];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    KKCommentM *comment=self.commentDatas[indexPath.row];
    return 90+[KKAppUtils sizeWithText:comment.commentcontent font:[UIFont systemFontOfSize:14] maxSize:CGSizeMake(screenWidth-61, MAXFLOAT)].height;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
        KKReplyVC *reply=[[KKReplyVC alloc] initWithNibName:@"KKReplyVC" bundle:nil];
        reply.commentInfo=self.commentDatas[indexPath.row];
        [[KKAppUtils getCurrentVisiableVC:self].navigationController pushViewController:reply animated:YES];
}
@end
